<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="afragment::head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>启事管理</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../../static/css/me.css" >
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  
</head>
<body>

  <!--导航-->
  <nav th:replace="afragment::menu(2)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small" >
    <div class="ui container">
      <div class="ui inverted secondary stackable menu">
        <h2 class="ui teal header item">后台管理</h2>
        <a href="UserManage.html" class="item"><i class="mini user icon"></i>人员管理</a>
        <a href="PostManage.html" class="item"><i class="mini file icon"></i>启事管理</a>
        <a href="NoticeManage.html" class="item"><i class="mini bell icon"></i>公告管理</a>
        <a href="FeedbackManage.html" class="item"><i class="mini envelope icon"></i>反馈管理</a>
        <a href="../static/index.html" class="item"><i class="mini home icon"></i>进入主页</a>
		<div class="right m-item  menu">
          <div class="ui dropdown  item">
            <div class="text" id="loginA">
              <img  class="ui avatar image" src="../static/images/HeadSculpture.jpg">
              Moon
            </div>
            <i class="dropdown icon"></i>
            <div class="menu">
              <a href="#" class="item">注销</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    
  </nav>
  
 	<div  class="m-container-small m-padded-tb-big">
	  <div class="ui container">
	    <form th:action="@{/admin/searchPost}" action="#" method="get" class="ui segment form">
	      <div class="inline fields">
				
	        <div class="field" style="margin-top: 1em;">
	          <input type="text" name="search" placeholder="输入查询内容">
	        </div>
	        <div class="field" style="margin-top: 1em;">
	          <button class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
	        </div>
	      </div>
	    </form>
	
	    <table class="ui celled table">
	      <thead>
	        <tr>
	          <th>postId</th>
	          <th>用户名</th>
	          <th>内容</th><!-- 启事的标题 -->
	          <th>创建时间</th>
			  <th>类型</th>
			  <th>状态</th>
	          <th>操作</th>
	        </tr>
	      </thead>
	      <tbody>
	        <tr th:each="post:${posts}">
	          <td th:text="${post.id}">1</td>
	          <td th:text="${post.uname}">Moon</td>
	          <td th:text="${post.content}">我的校园卡掉了</td>
	          <td th:text="${#dates.format(post.ctime,('yyyy-MM-dd HH:mm:ss'))}">2020-5-31 09:45</td>
			  <td th:text="${post.flag}==0?'寻物':'招领'">寻物</td>
			  <td th:if="${post.flag}==0" th:text="${post.status}==1?'正在寻找':'已经找到'">正在寻找</td>
			  <td th:if="${post.flag}==1" th:text="${post.status}==1?'等待认领':'已被认领'">正在寻找</td>
	          <td>
	            <button th:onclick="'Values('+${post.id}+')'" class="ui mini teal basic button"  data-toggle="modal" data-target="#myModal1">编辑</button>
	            <button th:onclick="'deletePost('+${post.id}+')'" class="ui mini red basic button">删除</button>
	          </td>
	        </tr>
	      </tbody>
	      <tfoot>
	        <tr>
	          <th colspan="7">
	            <div th:if="${pageInfo}!=null" class="ui mini pagination menu">
                    <label>总共[[${pageInfo.pages}]]页，当前第[[${pageInfo.pageNum}]]页</label>
                    <div class="column">
                        <a th:if="${pageInfo.prePage}!=0" th:href="${#request.getRequestURL()}+'?page='+${pageInfo.prePage}" class="ui teal basic button">上一页</a>
                    </div>
                    <div class="right aligned column">
                        <a th:if="${pageInfo.nextPage} <= ${pageInfo.pages}" th:href="${#request.getRequestURL()}+'?page='+${pageInfo.nextPage}" class="ui teal basic button">下一页</a>
                    </div>
	            </div>
	            <button  class="ui mini right floated green basic button"  data-toggle="modal" data-target="#myModal2">增加分类</button>

	          </th>
	        </tr>
	      </tfoot>
	    </table>
	  </div>
	</div>

    <!-- 第一个模态框 -->
    <form class="modal fade" id="myModal1" th:action="@{/admin/postStatus}" method="post">
      <div class="modal-dialog">
        <div class="modal-content">
     
          <!-- 模态框头部 -->
          <div class="modal-header">
            <i class="large edit icon"></i>修改物品状态
            <button type="button" class="close" data-dismiss="modal">&times;</button>
          </div>
     
          <!-- 模态框主体 -->
          <div class="modal-body">
            <div class="extra content">
              <input type="hidden" name="postID" id="postID">
              <label class="m-text-thin ">状态:</label>
              <div class="ui input focus">
<!--                <input type="text">-->
                  <select class="ui dropdown" name="status">
                      <option>已完成</option>
                      <option>进行中</option>
                  </select>
              </div>
            </div>
          </div>
     
          <!-- 模态框底部 -->
        <div class="modal-footer">
            <input type="submit" class="btn btn-success" value="确定">
		</div>
     
        </div>
      </div>
    </form>
    
 
  <!-- 第二个模态框 -->
 <div class="modal fade" id="myModal2">
      <div class="modal-dialog">
        <div class="modal-content">
     
          <!-- 模态框头部 -->
          <div class="modal-header">
            <i class="large edit icon"></i>增加分类
            <button type="button" class="close" data-dismiss="modal">&times;</button>
          </div>
     
          <!-- 模态框主体 -->
          <div class="modal-body">
            <div class="extra content">
              <label class="m-text-thin ">分类名称:</label>
              <div class="ui input focus">
                <input id="typename" type="text">
              </div>
            </div>
          </div>
     
          <!-- 模态框底部 -->
          <div class="modal-footer">
            <button type="button" class="btn btn-success" data-dismiss="modal" onclick="addType()" >确定</button>
          </div>
     
        </div>
      </div>
    </div>
    
  </div>


  <br>
  <br>
  <!-- 底部footer -->
  <footer th:replace="afragment::footer" class="ui inverted vertical segment m-padded-tb-massive ">
      <div class="ui center aligned container">
          <div class="ui inverted divided grid">
              <div class="three wide column">
                  <div class="ui inverted link list">
                      <div class="item">
                          <img src="../static/images/DLMU.svg" class="ui rounded image" alt="" style="width: 110px;">
                      </div>
                  </div>
              </div>
              <div class="three wide column">
                  <h4 class="ui inverted header m-text-thin m-text-spaced ">常见问题</h4>
                  <div class="ui inverted link list">
                      <a href="../problems.html" class="item">点击查看</a>
                      <a href="../feedback.html" class="item" >点击反馈</a>
                  </div>
              </div>
              <div class="three wide column">
                  <h4 class="ui inverted header m-text-thin m-text-spaced ">如何联系</h4>
                  <div class="ui inverted link list">
                      <a href="#" class="item m-text-thin">Email：xxxxxxxx@qq.com</a>
                      <a href="#" class="item m-text-thin">QQ：xxxxxxxx</a>
                  </div>
              </div>
              <div class="seven wide column">
                  <h4 class="ui inverted header m-text-thin m-text-spaced ">关于我们</h4>
                  <p class="m-text-thin m-text-spaced m-opacity-mini">LostFound</p>
              </div>
          </div>
          <div class="ui inverted section divider"></div>
          <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2025 - 3000 LostFound Designed by DLMU-LZT</p>
      </div>
  </footer>
  <!--	/*/<th:block th:replace="fragment::script">/*/-->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
  <!--    /*/</th:block>/*/-->

  <script>
    $('.ui.dropdown').dropdown({
      on : 'hover'
    });
	
	function addType(){
	    var typeName=$("#typename").val();
        $.ajax({
            url: "addType?typeName="+typeName,
            type: "get",
            async: true,
            success: function () {
                alert("添加成功");
            },
            error: function (error) {
                console.error(error);
            }
        });
	}
    function deletePost(postId) {
        $.ajax({
            url: "deletePost/"+postId,
            type: "delete",
            async: true,
            success: function () {
                alert("删除成功!");
                location.reload();
            },
            error: function (error) {
                console.error(error);
            }
        });
    }
    function Values(postID) {
        $('#postID').val(postID);
    }
	
  </script>
</body>
</html>